package com.hsgene.order.utils;

import com.hsgene.common.util.jwt.IJWTInfo;
import com.hsgene.common.util.jwt.JWTHelper;
import com.hsgene.common.util.jwt.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author wangbing
 * @version 1.0, 2018/10/15
 */
@Component
public class JwtToken {

    @Value("${jwt.expire}")
    private int expire;

    @Value("${jwt.pri-key.path}")
    private String priKeyPath;

    @Value("${jwt.pub-key.path}")
    private String pubKeyPath;

    private JwtTokenUtil jwtTokenUtil;

    @PostConstruct
    private void jwtTokenUtilInit() {
        jwtTokenUtil = new JwtTokenUtil(expire, priKeyPath, pubKeyPath);
    }

    public String generateToken(IJWTInfo jwtInfo) throws Exception {
        return jwtTokenUtil.generateToken(jwtInfo);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return jwtTokenUtil.getInfoFromToken(token);
    }
}
